<template>
  <el-dialog
    title="收货地址"
    :visible="updatevisible"
    @close="close"
    @open="getnodeInfo"
    width="630px"
  >
    <el-form :model="form">
      <el-form-item label="机器编号" label-width="120px">{{
        updatePolicyList.innerCode
      }}</el-form-item>
      <el-form-item label="供货时间" label-width="120px">
        {{ updatePolicyList.lastSupplyTime }}
      </el-form-item>
      <el-form-item label="设备类型" label-width="120px">
        {{ type.name }}
      </el-form-item>
      <el-form-item label="设备容量" label-width="120px">
        {{ type.channelMaxCapacity }}
      </el-form-item>
      <el-form-item label="设备点位" label-width="120px">
        <el-select
          v-model="form.nodeId"
          placeholder="请选择"
          style="width: 80%"
        >
          <el-option
            v-for="item in currentPageRecords"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="合作商" label-width="120px">
        {{ updatePolicyList.ownerName }}
      </el-form-item>
      <el-form-item label="所属区域" label-width="120px">
        {{ region.name }}
      </el-form-item>
      <el-form-item label="设备地址" label-width="120px">
        {{ node.name }}
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="updataList">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { getNodeInfo, putNodeInfo } from '@/api/device-manager'
export default {
  name: 'UpdateDialog',
  props: {
    updatevisible: {
      type: Boolean,
      required: true
    }
  },
  data () {
    return {
      form: {
        nodeId: ''
      },
      updatePolicyList: {},
      type: {},
      node: {},
      region: {},
      currentPageRecords: []
    }
  },
  methods: {
    close () {
      this.$emit('update:updatevisible', false)
    },
    // 点位
    async getnodeInfo () {
      this.type = this.updatePolicyList.type
      this.node = this.updatePolicyList.node
      this.region = this.node.region
      this.form.nodeId = this.node.id
      const { currentPageRecords } = await getNodeInfo({
        pageIndex: 1,
        pageSize: 1000
      })
      this.currentPageRecords = currentPageRecords
    },
    // 修改
    async updataList () {
      try {
        await putNodeInfo({ id: this.updatePolicyList.id, ...this.form })
        this.$message({ type: 'success', message: '修改成功' })
        this.close()
        this.$emit('updataList')
      } catch (e) {
        this.$message({ type: 'error', message: e.response.data })
      }
    }
  }
}
</script>

<style>
</style>
